package com.lifeng.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lifeng.common.util.PageResult;
import com.lifeng.entity.Type;
import com.lifeng.mapper.TypeMapper;
import com.lifeng.service.ITypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lifeng
 * @since 2025-01-13
 */
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type> implements ITypeService {
    @Override
    public PageResult<Type> findByPage(Integer page, Integer pageSize) {
        Page<Type> page1 = this.page(new Page<>(page, pageSize));
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }

    //分页查询（带条件）
    @Override
    public PageResult<Type> search(Integer page, Integer pageSize, String tname) {
        //封装查询条件
        QueryWrapper<Type> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(tname), "tname", tname);

        //根据wrapper包装好的条件进行分页查询
        Page<Type> page1 = this.page(new Page<>(page, pageSize), wrapper);
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }
}
